import 'package:learning/bean/result_entity.dart';
import 'package:learning/uitls/Request.dart';

import '../bean/category_entity.dart';
import '../bean/learning_type_entity.dart';

class CategoryService {
  static Future<List<CategoryEntity>> getCategoryList() async {
    var ddd = [];
    List<CategoryEntity> listData = [];
    ResultEntity data = await Request.get("category/list");
    if (data.success) {
      var ddd = data.data;
      print(ddd);

      for (var i = 0; i < ddd.length; i++) {
        CategoryEntity category = CategoryEntity.fromJson(ddd[i]);
        listData.add(category);
      }
      return listData;
    } else {
      throw Exception('Failed to load data');
    }
  }
  static Future<List<LearningTypeEntity>> getLearningTypeList() async {
    var ddd = [];
    List<LearningTypeEntity> listData = [];
    ResultEntity data = await Request.get("learningType/list");
    if (data.success) {
      var ddd = data.data;
      print(ddd);

      for (var i = 0; i < ddd.length; i++) {
        LearningTypeEntity category = LearningTypeEntity.fromJson(ddd[i]);
        listData.add(category);
      }
      return listData;
    } else {
      throw Exception('Failed to load data');
    }
  }
}
